package samples
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import marcel.display.draw.DrawManager;
	import marcel.display.draw.props.CornerProps;
	import marcel.display.draw.props.EllipseProps;
	import marcel.display.draw.props.FillProps;
	import marcel.display.draw.props.LineProps;
	import marcel.display.draw.props.PolygonProps;
	import marcel.utils.BitmapUtils;
	
	public class DrawManagerSample extends Sprite
	{
		
		protected var _fp:FillProps;
		protected var _fprg:FillProps;
		protected var _fplg:FillProps;
		protected var _lp:LineProps;
		protected var _dpo:DisplayObject;
		
		public function DrawManagerSample() {
			super();
			x = y = 20;
			_initProps();
			_drawRect();
			_drawEllipse();
			_drawStar();
			_drawPolygon();
			_drawPixel();
		}
		
		protected function _initProps():void {
			_fp = new FillProps(0xDDDDDD, .5);
			_fplg = new FillProps([0xDDDDDD, 0x555555], [.5,1], null, GradientType.LINEAR, 90);
			_fprg = new FillProps([0xDDDDDD, 0x555555], [.5,1], [50,60], GradientType.RADIAL);
			_lp = new LineProps(1, 0xFFFFFF, 1);
		}
		
		protected function _drawRect():void {
			var _r:Rectangle = new Rectangle(0, 0, 100, 100);
			var _cp:CornerProps = new CornerProps(25, false, 5);
			var _cpr:CornerProps = new CornerProps(10);
			
			DrawManager.drawRect(addChild(new Sprite()), _r, _fp, _lp, null);
			_dpo = DrawManager.drawRect(addChild(new Sprite()), _r, _fplg, null, _cp);
			_dpo.y = 105;
			_dpo = DrawManager.drawRect(addChild(new Sprite()), _r, _fprg, _lp, _cpr);
			_dpo.y = 210;
			_r = new Rectangle(0,0,50,100);
			_dpo = DrawManager.drawRect(addChild(new Sprite()), _r, _fp);
			_dpo.y = 315;
		}
		
		protected function _drawEllipse():void {
			var _ep:EllipseProps = new EllipseProps(new Point(50,10));
			_dpo = DrawManager.drawEllipse(addChild(new Sprite()), _ep, _fp, _lp);
			_dpo.x = 205;
			_dpo.y = 10;
			
			_ep = new EllipseProps(new Point(50,50));
			_dpo = DrawManager.drawEllipse(addChild(new Sprite()), _ep, _fplg, _lp);
			_dpo.x = 205;
			_dpo.y = 105;
			
			_ep = new EllipseProps(new Point(50,50), 2 * Math.PI / 3);
			_dpo = DrawManager.drawEllipse(addChild(new Sprite()), _ep, _fprg, _lp);
			_dpo.x = 205;
			_dpo.y = 230;
			
			_ep = new EllipseProps(new Point(50,50), 4 * Math.PI / 3, new Point(30,30));
			_dpo = DrawManager.drawEllipse(addChild(new Sprite()), _ep, _fp);
			_dpo.x = 205;
			_dpo.y = 315;
			
			_ep = new EllipseProps(new Point(50,10), 2 * Math.PI, new Point(30,5));
			_dpo = DrawManager.drawEllipse(addChild(new Sprite()), _ep, _fp, _lp);
			_dpo.x = 205;
			_dpo.y = 400;
		}
		
		protected function _drawStar():void {
			
			_dpo = DrawManager.drawStar(addChild(new Sprite()), 5, 50, 20, _fp, _lp);
			_dpo.x = 350;
			_dpo.y = 50;
			
			_dpo = DrawManager.drawStar(addChild(new Sprite()), 3, 50, 25, _fp, _lp);
			_dpo.x = 350;
			_dpo.y = 150;
			
			_dpo = DrawManager.drawStar(addChild(new Sprite()), 8, 50, 25, _fp);
			_dpo.x = 350;
			_dpo.y = 250;
			
			_dpo = DrawManager.drawStar(addChild(new Sprite()), 10, 50, 55, _fprg, _lp);
			_dpo.x = 350;
			_dpo.y = 375;
			
		}
		
		protected function _drawPolygon():void 
		{
			var _pp:PolygonProps = new PolygonProps(new Point(25,0), new Point(0,100), new Point(50,100));
			_dpo = DrawManager.drawPolygon(addChild(new Sprite()),_pp, false, _fplg);
			_dpo.x = 450;
			
			_pp = new PolygonProps(new Point(0,0), new Point(10,0), new Point(10, 100), new Point(60, 100), new Point(60, 110), new Point(0, 110));
			_dpo = DrawManager.drawPolygon(addChild(new Sprite()),_pp, true, _fplg, _lp);
			_dpo.x = 450;
			_dpo.y = 150;
			
			_pp = new PolygonProps(new Point(0,0), new Point(50,20), new Point(50, 80), new Point(0, 100));
			_dpo = DrawManager.drawPolygon(addChild(new Sprite()),_pp, true, _fprg, _lp);
			_dpo.x = 450;
			_dpo.y = 300;
		}
		
		protected function _drawPixel():void {
			var _map:String = "10000101001001010";
			var _bmpd:BitmapData = DrawManager.drawPixelAsset(BitmapUtils.getPixel(0xFF555555), _map.split(""), new Point(4,4));;
			var _bmp:Bitmap = new Bitmap(_bmpd);
			_bmp.x = 550;
			addChild(_bmp);

			_map = "";
			_map += "1      ";
			_map += "11     ";
			_map += "111    ";
			_map += "1111   ";
			_map += "11111  ";
			_map += "111111 ";
			_map += "1111111";
			_map += "111111 ";
			_map += "11111  ";
			_map += "1111   ";
			_map += "111    ";
			_map += "11     ";
			_map += "1      ";

			_bmpd = DrawManager.drawPixelAsset(_bmpd, _map.split(""), new Point(7,13));;
			_bmp = new Bitmap(_bmpd);
			_bmp.x = 550;
			_bmp.y = 50;
			addChild(_bmp);
			
			_map = "10000203004002030";
			
			
			var _colors:Array = new Array();
			for (var i:int = 0;i < 5; i++) {
				_colors.push(Math.round(Math.random() * 0xFFFFFF + 0xFF000000));
			}
			
			_bmpd = DrawManager.drawColoredPixelAsset(_bmpd, _colors, _map.split(""), new Point(4,4));;
			_bmp = new Bitmap(_bmpd);
			_bmp.x = 550;
			_bmp.y = 150;
			addChild(_bmp);
			
			var _s:Shape = DrawManager.getTrame(_bmpd, new Rectangle(0,0,800,600), null, false, true);
			_s.x = 0;
			_s.y = 0;
			//addChild(_s);
			

		}
		
	}
}